package com.aim.util;
import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.CharacterData;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

import android.util.Log;

public class ParseXMLString {

	
	public static ArrayList parseAllCase(String xmlRecords) {
	     
		
		ArrayList<Map<String,Object>> all = new ArrayList<Map<String,Object>>();
//	     boolean a = false;
	    try {
	        DocumentBuilderFactory dbf =
	            DocumentBuilderFactory.newInstance();
	        DocumentBuilder db = dbf.newDocumentBuilder();
	        InputSource is = new InputSource();
	        is.setCharacterStream(new StringReader(xmlRecords));

	        Document doc = db.parse(is);
	        NodeList nodes = doc.getElementsByTagName("Impound");

	        // iterate the employees
//	        06-13 16:09:26.815: ERROR/returnXML(1492): <Root><Impound><caseNo>79275</caseNo><carMake></carMake><carModel></carModel><carColor></carColor><carType></carType><vin></vin><imageCount>1</imageCount><carYear>1993</carYear><address></address><city></city><state></state><zip></zip><towReason>0</towReason><mileage>0</mileage><licensePlate></licensePlate><ImpoundNotes><seqNo>2147</seqNo><noteTitle>Vehicle Impounded</noteTitle><notes>Vehicle Impounded on 06/13/2011</notes><bookmark>0</bookmark></ImpoundNotes></Impound><Impound><caseNo>79273</caseNo><carMake></carMake><carModel></carModel><carColor></carColor><carType></carType><vin></vin><imageCount>0</imageCount><carYear>2001</carYear><address></address><city></city><state></state><zip></zip><towReason>1</towReason><mileage>123123</mileage><licensePlate></licensePlate><ImpoundNotes><seqNo>2144</seqNo><noteTitle>Vehicle Impounded</noteTitle><notes>Vehicle Impounded on 06/08/2011</notes><bookmark>0</bookmark></ImpoundNotes><ImpoundNotes><seqNo>2145</seqNo><noteTitle>asdasd</noteTitle><notes>asd</notes><bookmark>0</bookmark></ImpoundNotes></Impound><Impound><caseNo>79272</caseNo><carMake></carMake><carModel></carModel><carColor></carColor><carType></carType><vin></vin><imageCount>0</imageCount><carYear>5</carYear><address></address><city></city><state></state><zip></zip><towReason>2</towReason><mileage>0</mileage><licensePlate></licensePlate><ImpoundNotes><seqNo>2142</seqNo><noteTitle>Vehicle Impounded</noteTitle><notes>Vehicle Impounded on 06/07/2011</notes><bookmark>0</bookmark></ImpoundNotes><ImpoundNotes><seqNo>2143</seqNo><noteTitle>t</noteTitle><notes>n</notes><bookmark>0</bookmark></ImpoundNotes></Impound><Impound><caseNo>79271</caseNo><carMake>make</carMake><carModel>model</carModel><carColor>co</carColor><carType>type</carType><vin>vin</vin><imageCount>0</imageCount><carYear>1222</carYear><address>add</address><city>city</city><state>st</state><zip>1000</zip><towReason>2</towReason><mileage>10000</mileage><licensePlate>plate</licensePlate><ImpoundNotes><seqNo>2140</seqNo><noteTitle>Vehicle Impounded</noteTitle><notes>Vehicle Impounded on 06/07/2011</notes><bookmark>0</bookmark></ImpoundNotes><ImpoundNotes><seqNo>2141</seqNo><noteTitle>t</noteTitle><notes>n</notes><bookmark>1</bookmark></ImpoundNotes></Impound><Impound><caseNo>79270</caseNo><carMake></carMake><carModel></carModel><carColor></carColor><carType></carType><vin></vin><imageCount>0</imageCount><carYear>123</carYear><address></address><city></city><state></state><zip></zip><towReason></towReason><mileage>0</mileage><licensePlate></licensePlate><ImpoundNotes><seqNo>2139</seqNo><noteTitle>Vehicle Impounded</noteTitle><notes>Vehicle Impounded on 06/06/2011</notes><bookmark>0</bookmark></ImpoundNotes></Impound><Impound><caseNo>79269</caseNo><carMake></carMake><carModel></carModel><carColor></carColor><carType></carType><vin></vin><imageCount>0</imageCount><carYear>6</carYear><address></address><city></city><state></state><zip></zip><towReason></towReason><mileage>0</mileage><licensePlate></licensePlate><ImpoundNotes><seqNo>2138</seqNo><noteTitle>Vehicle Impounded</noteTitle><notes>Vehicle Impounded on 05/25/2011</notes><bookmark>0</bookmark></ImpoundNotes></Impound><Impound><caseNo>79268</caseNo><carMake></carMake><carModel></carModel><carColor></carColor><carType></carType><vin></vin><imageCount>2</imageCount><carYear>5</carYear><address></address><city></city><state></state><zip></zip><towReason></towReason><mileage>0</mileage><licensePlate></licensePlate><ImpoundNotes><seqNo>2135</seqNo><noteTitle>Vehicle Impounded</noteTitle><notes>Vehicle Impounded on 05/25/2011</notes><bookmark>0</bookmark></ImpoundNotes><ImpoundNotes><seqNo>2136</seqNo><noteTitle>Insert New Image from Android </noteTitle><notes>Insert New Image 79268_1.jpg from Android </notes><bookmark>0</bookmark></ImpoundNotes><ImpoundNotes><seqNo>2137</seqNo><noteTitle>Insert New Image from Android </noteTitle><notes>Insert New Image 79268_2.jpg from Android </notes><bookmark>0</bookmark></ImpoundNotes></Impound><Impound><caseNo>79267</caseNo><carMake>?</carMake><c

//	           Log.e("length","caseNo:" + nodes.getLength()+"    "+getCharacterDataFromElement((Element)nodes.item(1)));
	        for (int i = 0; i < nodes.getLength(); i++) {
//	        	Log.e("1","length: " + nodes.getLength());
	        	Map<String, Object> map = new HashMap<String, Object>();
	        	Element element = (Element) nodes.item(i);
//	        	Log.e("e1","element getname"+element.getTagName() +getCharacterDataFromElement(element));
	        	NodeList caseNo = element.getElementsByTagName("caseNo");
	           	Element line = (Element) caseNo.item(0);
//	        	Log.e("1","caseNo: " + getCharacterDataFromElement(line));
	        	map.put("no",getCharacterDataFromElement(line));
	           
	        	NodeList make = element.getElementsByTagName("carMake");	           
	        	line = (Element) make.item(0);	           
//	        	Log.e("2","make: " + getCharacterDataFromElement(line));
	        	map.put("make",getCharacterDataFromElement(line));
	        	
	        	NodeList model = element.getElementsByTagName("carModel");	           
	        	line = (Element) model.item(0);	           
//	        	Log.e("3","model: " + getCharacterDataFromElement(line));
	        	map.put("model",getCharacterDataFromElement(line));
	        	
	        	NodeList color = element.getElementsByTagName("carColor");	           
	        	line = (Element) color.item(0);	           
//	        	Log.e("3","model: " + getCharacterDataFromElement(line));
	        	map.put("color",getCharacterDataFromElement(line));
	        	
	        	NodeList type = element.getElementsByTagName("carType");
	           	line = (Element) type.item(0);	           
//	           	Log.e("4","type: " + getCharacterDataFromElement(line));
	           	map.put("type",getCharacterDataFromElement(line));
	           	
	           	NodeList vin = element.getElementsByTagName("vin");	           
	           	line = (Element) vin.item(0);	           
//	           	Log.e("5","vin: " + getCharacterDataFromElement(line));
	           	map.put("vin",getCharacterDataFromElement(line));
	           	
	        	NodeList imageCount = element.getElementsByTagName("imageCount");	           
	        	line = (Element) imageCount.item(0);	           
//	        	Log.e("6","imageCount: " + getCharacterDataFromElement(line));
	        	map.put("imageCount",getCharacterDataFromElement(line));
	        	
	        	NodeList year = element.getElementsByTagName("carYear");
	           	line = (Element) year.item(0);	           
//	           	Log.e("7","year: " + getCharacterDataFromElement(line));
	           	map.put("year",getCharacterDataFromElement(line));
	           	
	           	NodeList add1 = element.getElementsByTagName("address");	           
	           	line = (Element) add1.item(0);	           
//	           	Log.e("8","add: " + getCharacterDataFromElement(line));
	           	map.put("add",getCharacterDataFromElement(line));
	           	
	           	NodeList city = element.getElementsByTagName("city");	           
	           	line = (Element) city.item(0);	           
//	           	Log.e("9","city: " + getCharacterDataFromElement(line));
	           	map.put("city",getCharacterDataFromElement(line));
	           	
	           	NodeList state = element.getElementsByTagName("state");	           
	           	line = (Element) state.item(0);	           
//	           	Log.e("10","state: " + getCharacterDataFromElement(line));
	           	map.put("state",getCharacterDataFromElement(line));
	           	
	           	NodeList zip = element.getElementsByTagName("zip");	           
	           	line = (Element) zip.item(0);	           
//	           	Log.e("11","zip: " + getCharacterDataFromElement(line));
	           	map.put("zip",getCharacterDataFromElement(line));
	           	
	           	
	           	NodeList tow = element.getElementsByTagName("towReason");	           
	           	line = (Element) tow.item(0);	           
//	           	Log.e("12","tow: " + getCharacterDataFromElement(line));
	           	map.put("tow",getCharacterDataFromElement(line));
	           	
	           	NodeList mileage = element.getElementsByTagName("mileage");	           
	           	line = (Element) mileage.item(0);	           
//	           	Log.e("13","vin: " + getCharacterDataFromElement(line));
	           	map.put("mileage",getCharacterDataFromElement(line));
	           	
	           	NodeList plate = element.getElementsByTagName("licensePlate");	           
	           	line = (Element) plate.item(0);	           
//	           	Log.e("14",getCharacterDataFromElement(line));
	           	map.put("plate",getCharacterDataFromElement(line));
	           	
	           	NodeList date = element.getElementsByTagName("impoundDate");	           
	           	line = (Element) date.item(0);	           
	           	String d = getCharacterDataFromElement(line);
	           	d = d.substring(0, d.lastIndexOf("/"));
	           	map.put("date",d);
	           	if((d.length()-d.indexOf("/")) ==2)
	           	d= d.replaceAll("/", "0");
	           	else
	           	d = 	d.replaceAll("/", "");
	           	map.put("dateNo", d);
	           	
	           	
	           	int j=1;
					 
	           	try {
					NodeList Notes = element.getElementsByTagName("ImpoundNotes");
					Element noteLine1 = (Element) Notes.item(0);	           
//					Log.e("1",noteLine1.getTagName()+"  "  +getCharacterDataFromElement(noteLine1));
					NodeList seq1 = noteLine1.getElementsByTagName("seqNo");	
					line = (Element) seq1.item(0);	           
//					Log.e("2",line.getTagName()+"  "  +getCharacterDataFromElement(line));  
					map.put("seqNo"+0,getCharacterDataFromElement(line));
					
					seq1 = noteLine1.getElementsByTagName("noteTitle");
					line = (Element) seq1.item(0);	           
//					Log.e("2",line.getTagName()+"  "  +getCharacterDataFromElement(line));  
					map.put("noteTitle"+0,getCharacterDataFromElement(line));
					
					seq1 = noteLine1.getElementsByTagName("notes");
					line = (Element) seq1.item(0);	           
//					Log.e("2",line.getTagName()+"  "  +getCharacterDataFromElement(line));  
					map.put("notes"+0,getCharacterDataFromElement(line));
					
					seq1 = noteLine1.getElementsByTagName("bookmark");
					line = (Element) seq1.item(0);	           
//					Log.e("2",line.getTagName()+"  "  +getCharacterDataFromElement(line));  
					map.put("bookmark"+0,getCharacterDataFromElement(line));
					
					
					while(noteLine1!=null){
					Node seq2 = noteLine1.getNextSibling();
					noteLine1 = (Element) Notes.item(j);
					line = (Element) seq2;	     
//					Log.e("3",line.getTagName()+"  "  +getCharacterDataFromElement(line));
					seq1 = line.getElementsByTagName("seqNo");
					line = (Element) seq1.item(0);	
//					Log.e("3",line.getTagName()+"  "  +getCharacterDataFromElement(line)); 
					
					map.put("seqNo"+j,getCharacterDataFromElement(line));
					
					seq1 = noteLine1.getElementsByTagName("noteTitle");
					line = (Element) seq1.item(0);	           
//					Log.e("3",line.getTagName()+"  "  +getCharacterDataFromElement(line));  
					map.put("noteTitle"+j,getCharacterDataFromElement(line));
					
					seq1 = noteLine1.getElementsByTagName("notes");
					line = (Element) seq1.item(0);	           
//					Log.e("3",line.getTagName()+"  "  +getCharacterDataFromElement(line));  
					map.put("notes"+j,getCharacterDataFromElement(line));
					
					seq1 = noteLine1.getElementsByTagName("bookmark");
					line = (Element) seq1.item(0);	           
//					Log.e("3",line.getTagName()+"  "  +getCharacterDataFromElement(line));  
					map.put("bookmark"+j,getCharacterDataFromElement(line));
					
					j++;
					}
					
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
					
				}
				j=j-1;
				map.put("noteNo", j+"");
	           	
	           	
				
				
				
				
	          
	           	all.add(map);
	        }
	    }
	    catch (Exception e) {
	        e.printStackTrace();
	    }
	    return all;
	  }
	
public static Map<String, Object> parseCaseDetail(String xmlRecords) {
	     
		
		
	
		Map<String, Object> map = new HashMap<String, Object>();
//	     boolean a = false;
		NodeList nodes = null;
		NodeList table1 = null;
	        Document doc;
			try {
				DocumentBuilderFactory dbf =
				    DocumentBuilderFactory.newInstance();
				DocumentBuilder db = dbf.newDocumentBuilder();
				InputSource is = new InputSource();
				is.setCharacterStream(new StringReader(xmlRecords));

				doc = db.parse(is);
				nodes = doc.getElementsByTagName("Table");
				table1 = doc.getElementsByTagName("Table1");
			} catch (ParserConfigurationException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			} catch (SAXException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			} catch (IOException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
	        
	        
	        
	         
	       
//				Log.e("2???","  " +12312312+nodes.getLength()); 
//	           Log.e("length","caseNo:" + nodes.getLength()+"    "+getCharacterDataFromElement((Element)nodes.item(1)));
	        for (int i = 0; i < nodes.getLength(); i++) {
//	        	Log.e("1","length: " + nodes.getLength());
	        	
	        	Element element = (Element) nodes.item(i);
	        	NodeList caseNo = element.getElementsByTagName("caseNo");
	           	Element line = (Element) caseNo.item(0);
//	        	Log.e("1","caseNo: " + getCharacterDataFromElement(line));
	        	map.put("no",getCharacterDataFromElement(line));
	           
	        	try {
					NodeList make = element.getElementsByTagName("carmake");	           
					line = (Element) make.item(0);	           
//					Log.e("2","make: " + getCharacterDataFromElement(line));
					map.put("make",getCharacterDataFromElement(line));
				} catch (Exception e2) {
					// TODO Auto-generated catch block
					e2.printStackTrace();
				}
	        	
	        	try {
					NodeList model = element.getElementsByTagName("carModel");	           
					line = (Element) model.item(0);	           
//					Log.e("3","model: " + getCharacterDataFromElement(line));
					map.put("model",getCharacterDataFromElement(line));
				} catch (Exception e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
	        	
	        	try {
					NodeList color = element.getElementsByTagName("carcolor");	           
					line = (Element) color.item(0);	           
//					Log.e("3","color: " + getCharacterDataFromElement(line));
					map.put("color",getCharacterDataFromElement(line));
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
	        	
	        	try {
					NodeList type = element.getElementsByTagName("carType");
					line = (Element) type.item(0);	           
//					Log.e("4","type: " + getCharacterDataFromElement(line));
					map.put("type",getCharacterDataFromElement(line));
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
	           	
	           	try {
					NodeList vin = element.getElementsByTagName("vin");	           
					line = (Element) vin.item(0);	           
//					Log.e("5","vin: " + getCharacterDataFromElement(line));
					map.put("vin",getCharacterDataFromElement(line));
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
	           	
	        	NodeList imageCount = element.getElementsByTagName("imageCount");	           
	        	line = (Element) imageCount.item(0);	           
//	        	Log.e("6","imageCount: " + getCharacterDataFromElement(line));
	        	map.put("imageCount",getCharacterDataFromElement(line));
	        	
	        	try {
					NodeList year = element.getElementsByTagName("carYear");
					line = (Element) year.item(0);	           
//					Log.e("7","year: " + getCharacterDataFromElement(line));
					map.put("year",getCharacterDataFromElement(line));
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
	           	
	           	NodeList date = element.getElementsByTagName("impoundDate");	           
	           	line = (Element) date.item(0);	           
	           	String d = getCharacterDataFromElement(line);
	           	d = d.substring(5, 10);
	           	d= d.replaceAll("-", "/");
	           	map.put("date",d);
//	        	Log.e("date",d); 
//	           	if((d.length()-d.indexOf("/")) ==2)
	           	d= d.replaceAll("/", "");
//	           	else
//	           	d = 	d.replaceAll("/", "");
	           	map.put("dateNo", d);
	           
	           	
	           	try {
					NodeList add1 = element.getElementsByTagName("Address");	           
					line = (Element) add1.item(0);	           
//					Log.e("8","add: " + getCharacterDataFromElement(line));
					map.put("add",getCharacterDataFromElement(line));
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
	           	
	           	try {
					NodeList city = element.getElementsByTagName("city");	           
					line = (Element) city.item(0);	           
//					Log.e("9","city: " + getCharacterDataFromElement(line));
					map.put("city",getCharacterDataFromElement(line));
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
	           	
	           	try {
					NodeList state = element.getElementsByTagName("State");	           
					line = (Element) state.item(0);	           
//					Log.e("10","state: " + getCharacterDataFromElement(line));
					map.put("state",getCharacterDataFromElement(line));
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
	           	
	           	try {
					NodeList zip = element.getElementsByTagName("zip");	           
					line = (Element) zip.item(0);	           
//					Log.e("11","zip: " + getCharacterDataFromElement(line));
					map.put("zip",getCharacterDataFromElement(line));
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
	           	
	           	
	           	try {
					NodeList tow = element.getElementsByTagName("towReason");	           
					line = (Element) tow.item(0);	           
//					Log.e("12","tow: " + getCharacterDataFromElement(line));
					map.put("tow",getCharacterDataFromElement(line));
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
	           	
	           	try {
					NodeList mileage = element.getElementsByTagName("mileage");	           
					line = (Element) mileage.item(0);	           
//					Log.e("13","mileage: " + getCharacterDataFromElement(line));
					map.put("mileage",getCharacterDataFromElement(line));
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
	           	
	           	try {
					NodeList plate = element.getElementsByTagName("licensePlate");	           
					line = (Element) plate.item(0);	           
//					Log.e("14","plate: " + getCharacterDataFromElement(line));
					map.put("plate",getCharacterDataFromElement(line));
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
	           	

	        }
	      
	        
	        
	        for (int i = 0; i < table1.getLength(); i++) {
//	        	Log.e("2",i+"  "  +table1.getLength()); 
					 
	           	try {
					Element noteLine1 = (Element) table1.item(i);	           
					NodeList seq1 = noteLine1.getElementsByTagName("seqNo");	
					Element line = (Element) seq1.item(0);	           
//					Log.e("2",line.getTagName()+"  "  +getCharacterDataFromElement(line));  
					map.put("seqNo"+i,getCharacterDataFromElement(line));
					
					seq1 = noteLine1.getElementsByTagName("noteTitle");
					line = (Element) seq1.item(0);	           
//					Log.e("2",line.getTagName()+"  "  +getCharacterDataFromElement(line));  
					map.put("noteTitle"+i,getCharacterDataFromElement(line));
					
					seq1 = noteLine1.getElementsByTagName("notes");
					line = (Element) seq1.item(0);	           
//					Log.e("2",line.getTagName()+"  "  +getCharacterDataFromElement(line));  
					map.put("notes"+i,getCharacterDataFromElement(line));
					
					seq1 = noteLine1.getElementsByTagName("bookmark");
					line = (Element) seq1.item(0);	           
//					Log.e("2",line.getTagName()+"  "  +getCharacterDataFromElement(line));  
					map.put("bookmark"+i,getCharacterDataFromElement(line));
					
					
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
					
				}
				int no = table1.getLength()-1;
				map.put("noteNo", no+"");
	           	
	        }
	       
	   
	    return map;
	  }
	
	  public static boolean checkLoginKsoap(String xmlRecords) {
		     
		     boolean a = false;
		    try {
		        DocumentBuilderFactory dbf =
		            DocumentBuilderFactory.newInstance();
		        DocumentBuilder db = dbf.newDocumentBuilder();
		        InputSource is = new InputSource();
		        is.setCharacterStream(new StringReader(xmlRecords));

		        Document doc = db.parse(is);
		        NodeList nodes = doc.getElementsByTagName("user");

		        // iterate the employees
		        for (int i = 0; i < nodes.getLength(); i++) {
		           Element element = (Element) nodes.item(i);

//		           NodeList name = element.getElementsByTagName("u");
//		           Element line = (Element) name.item(0);
//		           System.out.println("Name: " + getCharacterDataFromElement(line));
		           NodeList title = element.getElementsByTagName("userStatus");
//		           NodeList title = element.getElementsByTagName("userStatus");
		           Element line = (Element) title.item(0);
		           Log.e("check ksoap","userstatus: " + getCharacterDataFromElement(line));

		           if (getCharacterDataFromElement(line).equals("A".trim())){
		        	   System.out.println(line);
		        	   a = true;
		        	   Log.e("parse a ", a+"");
		        	   break;
		           }
		           System.out.println("Title: " + getCharacterDataFromElement(line));
		        }
		    }
		    catch (Exception e) {
		        e.printStackTrace();
		    }
		    return a;
		  }
//  public static boolean checkLogin(String xmlRecords) {
//     
//     boolean a = false;
//    try {
//        DocumentBuilderFactory dbf =
//            DocumentBuilderFactory.newInstance();
//        DocumentBuilder db = dbf.newDocumentBuilder();
//        InputSource is = new InputSource();
//        is.setCharacterStream(new StringReader(xmlRecords));
//
//        Document doc = db.parse(is);
//        NodeList nodes = doc.getElementsByTagName("m:properties");
//
//        // iterate the employees
//        for (int i = 0; i < nodes.getLength(); i++) {
//           Element element = (Element) nodes.item(i);
//
//           NodeList name = element.getElementsByTagName("d:USER_ID");
//           Element line = (Element) name.item(0);
//           System.out.println("Name: " + getCharacterDataFromElement(line));
//           NodeList title = element.getElementsByTagName("d:STATUS");
////           NodeList title = element.getElementsByTagName("userStatus");
//           line = (Element) title.item(0);
//           System.out.println("userstatus: " + getCharacterDataFromElement(line));
//
//           if (getCharacterDataFromElement(line).equals("A".trim())){
//        	   System.out.println(line);
//        	   a = true;
//        	   Log.e("parse a ", a+"");
//        	   break;
//           }
//           System.out.println("Title: " + getCharacterDataFromElement(line));
//        }
//    }
//    catch (Exception e) {
//        e.printStackTrace();
//    }
//    return a;
//  }

  public static String getCharacterDataFromElement(Element e) {
    Node child = e.getFirstChild();
    if (child instanceof CharacterData&&(!child.equals(null))) {
       CharacterData cd = (CharacterData) child;
       return cd.getData();
    }
    return "";
  }
}